package com.yy.hi.okhttp2;

import java.util.HashMap;
import java.util.Map;

/**
 * User: gongyongfeng2@yy.com
 * Date: 2020/9/21 19 :51
 */
public class Request {
    final String url;
    final Method method;
    final RequestBody mRequestBody;
    final Map<String, String> headers;

    public Request(Builder builder) {
        this.url = builder.url;
        this.method = builder.method;
        this.mRequestBody = builder.mRequestBody;
        this.headers = builder.headers;
    }

    public static class Builder {
        private String url;
        private Method method;
        private RequestBody mRequestBody;
        private Map<String, String> headers = new HashMap<>();

        public Builder() {
            method = Method.GET;
            headers = new HashMap<>();
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder method(Method method) {
            this.method = method;
            return this;
        }

        public Builder get() {
            method = Method.GET;
            return this;
        }

        public void header(String key, String value) {
            headers.put(key, value);
        }

        public Builder post(RequestBody requestBody) {
            this.mRequestBody = requestBody;
            return this;
        }

        public Request build() {
            return new Request(this);
        }
    }
}
